﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
namespace JTicket.UI.Extention.IHandler
{
    public class TicketBookHandler : IHttpHandler
    {
        #region IHttpHandler Members

        public bool IsReusable
        {
            get { return false; }
        }

        public void ProcessRequest(HttpContext context)
        {
            HttpRequest request = context.Request;
            HttpResponse response = context.Response;
            string thcode = request.QueryString["ThCode"].ToString();
            string subcode = request.QueryString["SubCode"].ToString();
            string titlecode = request.QueryString["TitleCode"].ToString();
            string seatList = request.QueryString["SeatList"].ToString();
            string usertxt = request.QueryString["UserTxt"].ToString();
            string usertel = request.QueryString["UserTel"].ToString();
            string userAddress = request.QueryString["UserAddress"].ToString();
            string userUnit = request.QueryString["UserUnit"].ToString();
            string Flag = Common.StringHelp.GenerateFileName();
            BLL.D_OperInfo bllOper = new BLL.D_OperInfo();
            Model.D_OperInfo oper = bllOper.Oper();
            Model.SaleParm sale = new Model.SaleParm();
            List<string> aList = new List<string>();
            string[] arr = seatList.Replace("G", "").Split('|');
            aList = Common.CheckCode.ListBarCode(arr.Length - 1);
            string opercode = oper.OperCode;
            string ordercode = string.Format("J{0}", Flag);
            string saleip = HttpContext.Current.Request.UserHostAddress;
            bool res = false;
            if (arr.Length - 1 > 0)
            {
                for (int i = 0; i < arr.Length - 1; i++)
                {
                    sale.AreaCode = subcode;
                    sale.ICCode = "";
                    sale.IsSend = 0;
                    sale.Msg = "";
                    sale.PayModel = "现金";
                    sale.SaleModel = "";
                    sale.Sixid = arr[i];
                    sale.SumAmt = 0.0M;
                    sale.SumCount = 0;
                    sale.TaoCode = "";
                    sale.ThCode = thcode;
                    sale.TitleCode = titlecode;
                    sale.UnitCode = userUnit;
                    sale.UserAddress = userAddress;
                    sale.UserName = usertxt;
                    sale.UserTel = usertel;
                    sale.Zhekou = "10.0";
                    res = BLL.H_OrderBal.OrderBookTicket(sale, opercode, saleip, aList[i], Flag, "", Flag, "预留");
                }
            } if (res)
            {
                response.Write("预留成功！");
                response.End();
            }
            response.Write("预留失败！");
        }
        #endregion
    }
}
